﻿using Hangjing.Model;
using Hangjing.SQLServerDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_basicnew : System.Web.UI.Page
{
    Custorder bll = new Custorder();
    protected void Page_Load(object sender, EventArgs e)
    {
        Hangjing.Model.EAdminInfo model = UserHelp.GetAdmin();
        if (model != null)
        {
            this.snUsername.InnerHtml = model.AdminName;
            hfcityid.Value = model.CityID.ToString();
            shwoTodayOrder();
            shwoOrderStateSpan();
        }
        else
        {
            Response.Redirect("~/Admin/login.aspx");
        }
    }

    /// <summary>
    /// 今日订单
    /// </summary>
    protected void shwoTodayOrder()
    {
        string orderWhere = new RightsTool().getOrderWhere(" OrderDateTime > '" + DateTime.Now.ToShortDateString() + "' ");

        int[] hours = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
        IList<OrderCountInfo> shops = bll.GetOrderCount(7, "", "", "", orderWhere);
        string xjson = "";
        string yjson = "[";

        foreach (var hour in hours)
        {
            int ordercount = 0;
            decimal allprice = 0;
            foreach (var item in shops)
            {
                if (hour == Convert.ToInt32(item.CountKey))
                {
                    ordercount = item.CountIntValue;
                    allprice = item.CountDecimalValue;
                    break;
                }
            }
            yjson += "{'ordercount':" + ordercount + ",'allprice':" + allprice + "},";
        }


        xjson = WebUtility.dellast(xjson);
        yjson = WebUtility.dellast(yjson);

        yjson += "]";

        hfxjson.Value = xjson;
        hfyjson.Value = yjson;

    }

    /// <summary>
    /// 订单探状态分布
    /// </summary>
    protected void shwoOrderStateSpan()
    {
        string orderWhere = new RightsTool().getOrderWhere(" OrderDateTime > '"+DateTime.Now.ToShortDateString()+"' ");

        OrderState os = new OrderState();

        string xjson = "";
        IList<StateConfigInfo> ordersources = os.statelist;
        foreach (var item in ordersources)
        {
            xjson += item.classname + ",";
        }

        IList<OrderCountInfo> shops = bll.GetOrderByOrderState(orderWhere);

        string yjson = "[";

        foreach (var hour in ordersources)
        {
            int ordercount = 0;
            decimal allprice = 0;
            string name = hour.classname;
            foreach (var item in shops)
            {
                if (Convert.ToInt32(hour.Status) == Convert.ToInt32(item.CountKey))
                {
                    ordercount = item.CountIntValue;
                    allprice = item.CountDecimalValue;

                    break;
                }
            }
            yjson += "{'ordercount':" + ordercount + ",'allprice':" + allprice + ",'name':'" + name + "'},";
        }


        xjson = WebUtility.dellast(xjson);
        yjson = WebUtility.dellast(yjson);

        yjson += "]";

        hfxjson1.Value = xjson;
        hfyjson1.Value = yjson;

    }

}